<?php
/**
 * Created by JetBrains PhpStorm.
 * User: apple
 * Date: 1/23/14
 * Time: 2:08 PM
 * To change this template use File | Settings | File Templates.
 */

drupal_add_css(drupal_get_path('module', 'ticket_charge') . '/ticket_charge.css');

echo $charge_form;

?>

<?php if (variable_get('cardNumber') != null): ?>

<div class="info-contain">
    <div class="card-number-title">Số thẻ:</div>
    <div class="card-number-content"><?php echo variable_get('cardNumber'); ?> </div>

</div>
<table>
    <tr>
        <th>Tên vé</th>
        <th>Giá</th>
        <th>Bia miễn phí</th>
        <th>Kênh</th>
        <th>Quà</th>
        <th></th>
    </tr>
    <?php foreach (variable_get('ticketOfCard') as $item): ?>
                <tr id="record-<?php echo $item['card_ticket_id']; ?>" class="<?php echo ($item['status'] == Card_ticket::$status_available) ? 'available' : 'unavailable' ;  ?>">
                    <td><?php echo $item['type_name']; ?></td>
                    <td><?php echo $item['price']; ?></td>
                    <td><?php echo $item['free_beer']; ?></td>
                    <td><?php echo $item['channel']; ?></td>
                    <td><?php echo $item['gift']; ?></td>
                    <td>
                        <?php if($item['status'] == Card_ticket::$status_available): ?>
                        <input type="button" value="Lấy vé" record_id="<?php echo $item['card_ticket_id']; ?>" onclick="takeTicket($(this))" />
                        <?php endif; ?>
                    </td>
                </tr>
        <?php endforeach; ?>
</table>
    <?php endif; ?>

<script type="text/javascript">

    function takeTicket(obj){
        var recordId = obj.attr('record_id');

        $.ajax({
            url:'<?php echo base_path()?>/ajax-get-ticket',
            type:'POST',
            data:{
                recordId:recordId
            },
            success:function(data){
                obj.remove();
                $('#record-'+data).removeClass('available');
                $('#record-'+data).addClass('unavailable');
            }
        });
    }

    $(function(){

    });
</script>

<?php variable_set('ticketOfCard', null); ?>
<?php variable_set('cardNumber', null); ?>